package com.bingo.controller;

import com.bingo.common.R;
import com.bingo.entity.Medication;
import com.bingo.entity.Meteorology;
import com.bingo.entity.WaterQuality;
import com.bingo.entity.dto.req.ReqForm;
import com.bingo.service.MeteorologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/meteorology")
public class MeteorologyController {
    private MeteorologyService meteorologyService;

    @Autowired
    public void setMeteorologyService(MeteorologyService meteorologyService) {
        this.meteorologyService = meteorologyService;
    }

    @PostMapping("/record")
    public R meteorologyRecord(@RequestBody ReqForm reqForm) {
        return R.success(meteorologyService.selectMeteorologyRecord(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1], reqForm.getUserId()));
    }

    @PostMapping("/delete")
    public R deleteMeteorologyRecord(@RequestBody Meteorology meteorology) {
        boolean delete = meteorologyService.deleteMeteorologyRecord(meteorology);
        if (!delete) {
            return R.error("删除失败！");
        }
        return R.success("删除成功！");
    }

    @PostMapping("/add")
    public R addMeteorologyRecord(@RequestBody Meteorology meteorology) {
        return meteorologyService.add(meteorology);
    }
    @PostMapping("/update")
    public R updateMeteorologyRecord(@RequestBody Meteorology meteorology) {
        return R.success(meteorologyService.update(meteorology));
    }
}